<html>
<head><meta charset="utf-8"><title>Synchronizing non-atomics with atomics · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html">Synchronizing non-atomics with atomics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223748263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Synchronizing%20non-atomics%20with%20atomics/near/223748263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html#223748263">(Jan 23 2021 at 12:55)</a>:</h4>
<p>Hey! Is it possible to synchronize non-atomic operations with atomic operations in Rust? FWIU this is possible in C++, and the documentation for Rust's std::sync::atomic says the memory ordering model is the same as in C++ - but is there a way to actually share a reference to implicitly-synchronized non-atomic variables across threads?</p>



<a name="223748518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Synchronizing%20non-atomics%20with%20atomics/near/223748518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html#223748518">(Jan 23 2021 at 13:01)</a>:</h4>
<p>unsafecell?</p>



<a name="223749109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Synchronizing%20non-atomics%20with%20atomics/near/223749109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html#223749109">(Jan 23 2021 at 13:16)</a>:</h4>
<p>Thanks! Looks like UnsafeCell is !Sync, how would I share this across threads?</p>



<a name="223749532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Synchronizing%20non-atomics%20with%20atomics/near/223749532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html#223749532">(Jan 23 2021 at 13:25)</a>:</h4>
<p>You can implement <code>Sync</code> on a wrapper around <code>UnsafeCell</code>.</p>



<a name="223749540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Synchronizing%20non-atomics%20with%20atomics/near/223749540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html#223749540">(Jan 23 2021 at 13:25)</a>:</h4>
<p>Just make sure that you enforce correct synchronization.</p>



<a name="223749815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Synchronizing%20non-atomics%20with%20atomics/near/223749815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Synchronizing.20non-atomics.20with.20atomics.html#223749815">(Jan 23 2021 at 13:33)</a>:</h4>
<p>Aha, thank you :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>